package local.blueheart.data.springdatademo.listener;

import local.blueheart.data.springdatademo.service.XmlConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;

@Component
@Order(2)
public class XMLConfigParserListener implements CommandLineRunner, ResourceLoaderAware {

    private ResourceLoader resourceLoader;

    @Autowired
    private XmlConfigService xmlConfigService;


    @Override
    public void run(String... args) throws Exception {
        Resource resource = resourceLoader.getResource("classpath:/dataproconf.xml");
        xmlConfigService.initConfig(resource.getURL());
    }

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }
}
